//
//  ShowTipAndContentClickCell.m
//  ppkc2016
//
//  Created by 拼凑的断音 on 16/3/29.
//  Copyright © 2016年 拼凑的断音. All rights reserved.
//

#import "ShowTipAndContentClickCell.h"
#import "XXTool.h"

@implementation XMLNameAndValueModel

@end

@interface ShowTipAndContentClickCell ()

@property (nonatomic) UILabel *leftTipLabel;

@property (nonatomic) UILabel *rightContentLabel;

@property (nonatomic) UIView *rightMaskView;

@property (nonatomic) UIImageView *rightMask_arrow;

@end

@implementation ShowTipAndContentClickCell
{
    XMLNameAndValueModelType useType;
    CGFloat leftLabelWidth;
}

-(UILabel*)leftTipLabel
{
    if (_leftTipLabel==nil)
    {
        _leftTipLabel = [[UILabel alloc] init];
        _leftTipLabel.numberOfLines = 0;
        _leftTipLabel.textColor = [UIColor blackColor];
        _leftTipLabel.font = [XXTool systemFontOfSize:16.5f];
        [self addSubview:_leftTipLabel];
    }
    return _leftTipLabel;
}

-(UILabel*)rightContentLabel
{
    if (_rightContentLabel==nil)
    {
        _rightContentLabel = [[UILabel alloc] init];
        _rightContentLabel.numberOfLines = 0;
        _rightContentLabel.textColor = [UIColor blackColor];
        _rightContentLabel.font = [XXTool systemFontOfSize:16.5f];
        [self addSubview:_rightContentLabel];
    }
    return _rightContentLabel;
}

-(UIView*)rightMaskView
{
    if (_rightMaskView==nil)
    {
        _rightMaskView = [[UIView alloc] init];
        _rightMaskView.backgroundColor = [UIColor colorWithRed:227/255.0 green:228/255.0 blue:229/255.0 alpha:1.0];
        _rightMaskView.layer.cornerRadius = 5;
        [self addSubview:_rightMaskView];
    }
    return _rightMaskView;
}

-(UIImageView*)rightMask_arrow
{
    if (_rightMask_arrow==nil)
    {
        _rightMask_arrow = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"展位按钮箭头"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
        _rightMask_arrow.tintColor = [XXTool colorWithProject];
        _rightMask_arrow.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_rightMask_arrow];
    }
    return _rightMask_arrow;
}

-(void)initParameter
{
    leftLabelWidth = [XXTool getWidthWithScreenWidth:232];
}

-(void)initUI
{
    [self leftTipLabel];
    [self rightMaskView];
    [self rightMask_arrow];
    [self rightContentLabel];
}

-(void)refreshLayout:(CGRect)frame
{
    CGFloat leftHeight = [XXTool getTextHeightByText:_leftTipLabel.text Font:_leftTipLabel.font Width:leftLabelWidth];
    CGFloat rightHight = [XXTool getTextHeightByText:_rightContentLabel.text Font:_rightContentLabel.font Width:([UIScreen mainScreen].bounds.size.width-leftLabelWidth-20*2)];
    
    
    _leftTipLabel.frame = CGRectMake(20
                                     , 22
                                     , leftLabelWidth, leftHeight);
    _rightContentLabel.frame = CGRectMake(_leftTipLabel.frame.size.width+_leftTipLabel.frame.origin.x
                                          , _leftTipLabel.frame.origin.y
                                          , [UIScreen mainScreen].bounds.size.width-leftLabelWidth-20*2
                                          , rightHight);
    
    if (useType==XMLNameAndValueModelNeedClick)
    {
        _rightMaskView.hidden = NO;
        _rightMask_arrow.hidden = NO;
        _rightMaskView.frame = CGRectMake(_rightContentLabel.frame.origin.x-10
                                          , (frame.size.height-30)/2
                                          , [XXTool getTextWidthByText:_rightContentLabel.text
                                                                  Font:_rightContentLabel.font]+30
                                          , 30);
        _rightMask_arrow.frame = CGRectMake(_rightMaskView.frame.origin.x+_rightMaskView.frame.size.width-10-7
                                            , _rightMaskView.frame.origin.y+(30-13)/2
                                            , 7
                                            , 13);
        
    }
    else
    {
        _rightMaskView.hidden = YES;
        _rightMask_arrow.hidden = YES;
    }
}

-(void)setCellWithData:(XMLNameAndValueModel *)model
{
    useType = model.useType;
    _leftTipLabel.text = model.name;
    _rightContentLabel.text = model.value;
    [self refreshLayout:self.frame];
}

+(CGFloat)getCellHeightWithData:(XMLNameAndValueModel *)model
{
    CGFloat leftHeight = [XXTool getTextHeightByText:model.name Font:[XXTool systemFontOfSize:16.5f]
                                            Width:[XXTool getWidthWithScreenWidth:232]];
    CGFloat rightHight = [XXTool getTextHeightByText:model.value Font:[XXTool systemFontOfSize:16.5f] Width:([UIScreen mainScreen].bounds.size.width-[XXTool getWidthWithScreenWidth:232]-20*2)];
    
    return 22*2+(leftHeight>=rightHight?leftHeight:rightHight);
}

@end
